package de.hska.algo.labor2010.strecken;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

public class GridTest {
	
	
	

	@Test
	public void testInitialize() {
		Grid grid = new Grid();
		ArrayList<Line> lines = new ArrayList<Line>();
		lines.add(new Line(1,5,5,1));
		lines.add(new Line(0,0,10,10));
		grid.initialize(lines,5);
		ArrayList<Line> lines2 = new ArrayList<Line>();
		lines2.add(new Line(1,2,5,5));
		lines2.add(new Line(0,1,8,8));
		lines2.add(new Line(0.0,0.5,10,0.5));
		lines2.add(new Line(0,0,1,8));
		lines2.add(new Line(0,9,9,0));
		lines2.add(new Line(0,0,10,10));
		grid.initialize(lines2, 5);
		assertEquals(25, grid.getGrid().size());
		assertEquals(0,grid.getMinX(),1.9e-16);
		assertEquals(0,grid.getMinY(),1.9e-16);
		assertEquals(10,grid.getMaxX(),1.9e-16);
		assertEquals(10,grid.getMaxY(),1.9e-16);
		assertEquals(-1.5,grid.getGrid().get(0).getLowerLeft().getX(),1.9e-17);
		assertEquals(-1.5,grid.getGrid().get(0).getLowerLeft().getY(),1.9e-17);
		assertEquals(13.5,grid.getGrid().get(grid.getGrid().size()-1).getUpperRight().getX(),1.9e-17);
		assertEquals(13.5,grid.getGrid().get(grid.getGrid().size()-1).getUpperRight().getY(),1.9e-17);
		
		}

	@Test
	public void testIntersect() {
		ArrayList<Line> lines = new ArrayList<Line>();
		lines.add(new Line(0,0,10,10));
		lines.add(new Line(1,0,8,10));
		lines.add(new Line(0,5,10,5));
		Grid grid = new Grid();
		ArrayList<Point> result = (ArrayList<Point>) grid.intersectAndInitialize(lines, 5);
		assertEquals(3,result.size());
		//assertEquals((double)(10/3),result.get(0).getX(),1.9e-16);
		//assertEquals(1/3,result.get(0).getX(),1.9e-16);
		assertEquals(5.0,result.get(1).getX(),1.9e-16);
		assertEquals(5.0,result.get(1).getY(),1.9e-16);
		assertEquals(4.5,result.get(2).getX(),1.9e-16);
		assertEquals(5.0,result.get(2).getY(),1.9e-16);
		
	}
	
	

	@Test
	public void testIntersectAndInitialize() {
		
	}

	@Test
	public void testToString() {
		Grid grid = new Grid(5);
		String sth = "";
		assertEquals(sth,grid.toString());
	}
	
	@Test
	public void testGrid(){
		Grid grid = new Grid(5);
		grid = new Grid(5,100);
		grid = new Grid();
	}
}
